package flc.ast.fragment;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.stark.calculator.mortgage.BaseMortFragment;
import com.stark.calculator.mortgage.model.LoanModel;

import flc.ast.R;
import flc.ast.activity.HouseAllResultActivity;
import flc.ast.activity.HouseResultActivity;
import flc.ast.databinding.FragmentHouseKind3Binding;
import stark.common.basic.view.InputUnitView;
import stark.common.basic.view.TextSwitch;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HouseKind3Fragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HouseKind3Fragment extends BaseMortFragment<FragmentHouseKind3Binding> {

    @Override
    protected InputUnitView getFundAmountView() {
        return mDataBinding.iuHouseKind3Gjjje;
    }

    @Override
    protected InputUnitView getFundInterestView() {
        return mDataBinding.iuHouseKind3Gjjll;
    }

    @Override
    protected InputUnitView getCommercialAmountView() {
        return mDataBinding.iuHouseKind3SyDkje;
    }

    @Override
    protected TextSwitch getInterestMethodView() {
        return mDataBinding.tsSwitch;
    }

    @Override
    protected View getLprBasisContainer() {
        return mDataBinding.llHouseKind3LprView;
    }

    @Override
    protected View getBaseInterestContainer() {
        return mDataBinding.llHouseKind3JzllView;
    }

    @Override
    protected InputUnitView getLprView() {
        return mDataBinding.iuHouseKind3Lpr;
    }

    @Override
    protected TextSwitch getBasisAddSubView() {
        return mDataBinding.tsHouseKind3Switch;
    }

    @Override
    protected InputUnitView getBasisInputView() {
        return mDataBinding.iuHouseKind3Jd;
    }

    @Override
    protected InputUnitView getCommercialInterestView() {
        return mDataBinding.iuHouseKind3SyDkll;
    }

    @Override
    protected InputUnitView getInterestDiscountView() {
        return mDataBinding.iuHouseKind3Syllzk;
    }

    @Override
    protected InputUnitView getYearView() {
        return mDataBinding.iuHouseKind3Dknx;
    }

    @Override
    protected TextSwitch getLoanMethodView() {
        return null;
    }

    @Override
    protected int onCreate() {
        return R.layout.fragment_house_kind3;
    }

    @Override
    protected void initData() {
        mDataBinding.tvCalculate.setOnClickListener(this);
        mDataBinding.tvHouseKind3Lpr.setOnClickListener(this);
        mDataBinding.tvHouseKind3Jzll.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvHouseKind3Lpr:
                clearSelection();
                mDataBinding.tvHouseKind3Lpr.setBackgroundResource(R.drawable.shape_rate_type);
                mDataBinding.tvHouseKind3Lpr.setTextColor(Color.WHITE);
                mDataBinding.llHouseKind3LprView.setVisibility(View.VISIBLE);
                break;
            case R.id.tvHouseKind3Jzll:
                clearSelection();
                mDataBinding.tvHouseKind3Jzll.setBackgroundResource(R.drawable.shape_rate_type);
                mDataBinding.tvHouseKind3Jzll.setTextColor(Color.WHITE);
                mDataBinding.llHouseKind3JzllView.setVisibility(View.VISIBLE);
                break;
            case R.id.tvCalculate:
                calculate();
                break;
        }
    }

    @Override
    protected void goRetActivity(LoanModel loanModel) {
        HouseAllResultActivity.loanModel = loanModel;
        startActivity(HouseAllResultActivity.class);
    }

    private void clearSelection() {
        mDataBinding.tvHouseKind3Jzll.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvHouseKind3Jzll.setBackground(null);
        mDataBinding.tvHouseKind3Lpr.setTextColor(Color.parseColor("#000000"));
        mDataBinding.tvHouseKind3Lpr.setBackground(null);
        mDataBinding.llHouseKind3JzllView.setVisibility(View.GONE);
        mDataBinding.llHouseKind3LprView.setVisibility(View.GONE);
    }

}